package api.practice01;

import java.awt.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

public class CollectionDemo {
    public static void main(String[] args) {
        Collection<String> cc = new ArrayList<>();
        cc.add("one");
        cc.add("1");
        cc.add("two");
        cc.add("2");
        cc.add("three");
        cc.add("3");
        cc.add("four");
        cc.add("4");
        cc.add("five");
        cc.add("5");
        Collection<Point> p = new ArrayList<>();
        p.add(new Point(3, 4));
        p.add(new Point(4, 5));
        p.add(new Point(5, 6));
        p.add(new Point(6, 7));
        System.out.println("集合长度是" + cc.size());

        boolean b = cc.isEmpty();
        System.out.println("集合是否是空的" + b);
        //  cc.clear();
        boolean b1 = cc.isEmpty();
        System.out.println(b1);

        cc.remove("one");
        System.out.println(cc);

        Collection<String> c1 = new ArrayList<>();
        c1.add("six");
        c1.add("seven");
        cc.addAll(c1);
        System.out.println(c1);
        System.out.println(cc);
        boolean b3 = cc.containsAll(c1);
        System.out.println(b3);
        // boolean b4 = cc.retainAll(c1);
        boolean b5 = cc.removeAll(c1);
        System.out.println(cc);


        Iterator<String> it = cc.iterator();
        while (it.hasNext()) {
            String s = it.next();
            if ("two".equals(s)) {
                it.remove();
            }

        }
        System.out.println(cc);

       /* Point p1 = new Point(5,6);
        boolean b2 = p.contains(p1);
        System.out.println(b2);*/

        Collection<String> c = new ArrayList<>();
        c.add("one");
        c.add("two");
        c.add("three");
        c.add("four");
        c.add("five");
        System.out.println(c);
        String[]  st = c.toArray(new String[0]);
        System.out.println(Arrays.toString(st));//转为数组


        List<String> list = Arrays.asList(st);//转为集合
        System.out.println(list);
        st[4] ="5";//数组改变后,集合也会相应的改变
        System.out.println(list);
        list.set(3,"4");//集合改变厚,数组也会改变
        System.out.println(Arrays.toString(st));
        //list.add("!!!");//发生不支持操作异常







    }
}
